"""Defines the "google command".

Copyright Ian Blumel, 2009.
All Rights Reserved.
"""

from libskysh.cmd import cmd_t

class google_cmd_t(cmd_t):
    name = "google"
    short_desc = "returns a google hyperlink"
    desc = """\
usage: google arg1 arg2 arg3 ...
Converts N ARGS to a single google query. If no arguments
returns a link to google."""
    
    def __init__(self, *args):
        cmd_t.__init__(self, *args)
        self.name = "google"

    def execute(self, argv):
        if len(argv) == 1:
            # TODO locate the google country code (ca, au, nz, &etc).
            self.write("http://www.google.com")
        else:
            # TODO properly quote up the argument, and escape characters.
            query = "+".join(argv[1:])
            url = "http://www.google.com/search?q="+query
            self.write(url)
